package com.ypd.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ypd.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.shop.domain.PostBox;
import com.ypd.shop.service.IPostBoxService;
import com.ypd.common.utils.poi.ExcelUtil;
import com.ypd.common.core.page.TableDataInfo;

/**
 * 邮箱Controller
 * 
 * @author lin
 * @date 2025-02-22
 */

@RestController
@RequestMapping("/shop/box")
@Api(tags = "邮箱Controller")
public class PostBoxController extends BaseController
{
    @Autowired
    private IPostBoxService postBoxService;

    /**
     * 查询邮箱列表
     */
    @ApiOperation("查询邮箱列表")
    @GetMapping("/list")
    public TableDataInfo list(PostBox postBox)
    {
        startPage();
        List<PostBox> list = postBoxService.selectPostBoxList(postBox);
        return getDataTable(list);
    }

    /**
     * 导出邮箱列表
     */
    @ApiOperation("导出邮箱列表")

    @Log(title = "邮箱", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostBox postBox)
    {
        List<PostBox> list = postBoxService.selectPostBoxList(postBox);
        ExcelUtil<PostBox> util = new ExcelUtil<PostBox>(PostBox.class);
        util.exportExcel(response, list, "邮箱数据");
    }

    /**
     * 获取邮箱详细信息
     */
    @ApiOperation("获取邮箱详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(postBoxService.selectPostBoxById(id));
    }

    /**
     * 新增邮箱
     */
    @ApiOperation("新增邮箱")
    @Log(title = "邮箱", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostBox postBox)
    {
        return toAjax(postBoxService.insertPostBox(postBox));
    }

    /**
     * 修改邮箱
     */
    @ApiOperation("修改邮箱")
    @Log(title = "邮箱", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostBox postBox)
    {
        return toAjax(postBoxService.updatePostBox(postBox));
    }

    /**
     * 删除用户邮箱
     */
    @ApiOperation("删除邮箱")
    @Log(title = "邮箱", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(postBoxService.deletePostBoxByIds(ids));
    }
}
